package ar.uba.fi.tecnicas.juego;

import java.awt.Dimension;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import ar.uba.fi.tecnicas.fabrica.Terreno;

public class ConfiguracionTerreno extends ConfiguracionItems<Terreno>
{
	public final static ConfiguracionTerreno instance = new ConfiguracionTerreno();
	
	protected ConfiguracionTerreno()
	{
		super();
	}
	
	protected void LoadData()
	{
		Document xml = ConfiguracionJuego.instancia.obtenerXml();
		
		Element parentElement = this.getChildElement(xml.getDocumentElement(), "Terrenos");
		NodeList list = parentElement.getElementsByTagName("Terreno");
		
		for(int index = 0; index < list.getLength(); index++)
		{
			if(list.item(index).getNodeType() == Node.ELEMENT_NODE)
			{
				Element terrenoElement = (Element)list.item(index);
				
				String ancho = this.getElementValue(this.getChildElement(terrenoElement, "Ancho"));
				String alto = this.getElementValue(this.getChildElement(terrenoElement, "Alto"));
				String precioCompra = this.getElementValue(this.getChildElement(terrenoElement, "PrecioCompra"));
				String precioAlquiler = this.getElementValue(this.getChildElement(terrenoElement, "PrecioAlquiler"));
				
				Terreno terreno = new Terreno(
					new Dimension(
						Integer.valueOf(ancho),
						Integer.valueOf(alto)
					),
					Double.valueOf(precioAlquiler),
					Double.valueOf(precioCompra)
				);

				this.items.put(String.valueOf(index), terreno);
			}
		}
	}
}
